// C source file with the function definitions to handle BDL's TEX1 section
// little trick to evade having to rebuild the TEX1 functions >:]

// function to avoid having to do a complete copy/paste
// of check_j3dgraph_bmd_tex1() into check_j3dgraph_bdl_tex1()
void j3dgraph_bdl_tex1_adjust(bool cond);
void j3dgraph_bdl_tex1_adjust(bool cond)
{
  if (cond) {
    J3DGRAPH_BMD_TEX1_POS = J3DGRAPH_BDL_TEX1_POS;
    J3DGRAPH_BMD_SEC_START[8][0] = J3DGRAPH_BDL_SEC_START[8][0];
    J3DGRAPH_BMD_SEC_START[8][1] = J3DGRAPH_BDL_SEC_START[8][1];
  }
  else {
    J3DGRAPH_BMD_TEX1_POS--;
    J3DGRAPH_BMD_SEC_START[8][0] = NULL;
    J3DGRAPH_BMD_SEC_START[8][1] = NULL;
  }
}

// check_j3dgraph_bdl_tex1() function
// function to check if the TEX1 section of a BDL is valid
bool check_j3dgraph_bdl_tex1(j3dgraph * file)
{
  j3dgraph_bdl_tex1_adjust(true);
  bool rtn = check_j3dgraph_bmd_tex1(file);
  j3dgraph_bdl_tex1_adjust(false);
  return rtn;
}

// append_j3dgraph_bdl_tex1() function
// append a j3dgraph_bdl_tex1 struct to an incomplete j3dgraph struct
j3dgraph_bdl_tex1 * append_j3dgraph_bdl_tex1(j3dgraph * file)
{  
  j3dgraph_bdl_tex1_adjust(true);
  j3dgraph_bdl_tex1 * rtn = append_j3dgraph_bmd_tex1(file);
  j3dgraph_bdl_tex1_adjust(false);
  return rtn;
}

// remove_j3dgraph_bdl_tex1() function
// function to remove a j3dgraph_bdl_tex1 structure from a j3dgraph structure
void remove_j3dgraph_bdl_tex1(j3dgraph * file)
{
  j3dgraph_bdl_tex1_adjust(true);
  remove_j3dgraph_bmd_tex1(file);
  j3dgraph_bdl_tex1_adjust(false);
  return;
}

// print_j3dgraph_bdl_tex1() function
// print the information of the TEX1 section of a BDL
void print_j3dgraph_bdl_tex1(j3dgraph_bdl_tex1 * tex1)
{
  j3dgraph_bdl_tex1_adjust(true);
  print_j3dgraph_bmd_tex1(tex1);
  j3dgraph_bdl_tex1_adjust(false);
  return;
}
